﻿@{
    ViewBag.Title = "jiesuan";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<link href="~/Content/default/jiesuan.css" rel="stylesheet" />
@using System.Data
@using RBS.Common
@model RBS.Web.Hotel.Models.Order.OrderViewModel

@*<div class="line5"></div>
@using (Ajax.BeginForm("jiesuan", new AjaxOptions { OnSuccess = "OnSuccess" }))
{  
    @Html.HiddenFor(model => model.OrderModel.Id);
    @Html.HiddenFor(model => model.OrderModel.H_Id);
    @Html.HiddenFor(model => model.OrderModel.DineTable);
    @Html.HiddenFor(model => model.OrderModel.U_Id); 
    @Html.HiddenFor(model => model.UserIntegration); 
    <div class="content-tab-wrap">
        <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected">结算金额</a></li>

                    <li><a href="javascript:;" onclick="tabs(this);">订单详情</a></li>
                </ul>
            </div>
        </div>
    </div>
    <table class="ltable">
        <tr>
            <td>结帐单号：@Html.DisplayFor(model => model.Number)</td>
            <td>结账台号：@Model.SeateName</td>

        </tr>
    </table> 
    <div class="line5"></div>
    <table class="ltable">
        <tr>
            <td>消费金额：@Model.OrderModel.OrderAmount</td>
            <td>就餐人数：  @Html.TextBoxFor(model => model.OrderModel.DineNum, null, new { @class = "input small" }) 人</td>
        </tr>
    </table>
    <div class="line5"></div> 
    <table class="ltable">
        <tr>
            <td>会员编号/姓名：  @Html.DisplayFor(model => model.User.U_Name)</td>
            <td>会员积分：@Model.UserIntegration （可抵用 @String.Format("{0}", Model.UserIntegration / 100.00) 元）</td>
        </tr>
    </table>
    <div class="clear"></div> 
    <div class="tab-content">
        <dl>
            <dt>支付方式：</dt>
            <dd>
                <div class="rule-single-select">
                    @Html.DropDownListFor(model => model.Seetlement.PayType,
                                                          new[] { new SelectListItem() { Text = "现金", Value = "现金" }, 
                                                              new SelectListItem() { Text = "刷卡", Value = "刷卡" },
                                                          })
                </div>
            </dd>
        </dl> 
        <dl>
            <dt>消费金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.OrderAmount, new { @class = "input small jine", @readonly = "readonly" })元</dd>
        </dl> 
        @{
                                                   if (Model.User != null)
                                                   {
            <dl>
                <dt>积分抵扣：</dt>
                <dd>@Html.TextBoxFor(model => model.Seetlement.JF, "0", new { @class = "input small jine" }) 分 </dd>  
            </dl>
            <dl>
                <dt>优惠券使用：</dt>
                <dd>
                    @Html.HiddenFor(model => model.Seetlement.AdvertisId) 
                    @{ 
                        <ul>
                            @if (Model.UserDeed == null)
                            {
                                <li>无优惠卷信息</li>
                            }
                            else
                            {
                            foreach (var row in Model.UserDeed)
                            { 
                                if(row.DeedType==1){
                                    <li> 
                                        <input id="@row.Id" type="checkbox"  name="SendFood" datatype="max2" value="@row.Id" /> 
                                        <label for="@row.Id">@row.Crowd [送采券]</label> 
                                    </li>
                                }
                                if (row.DeedType == 2)
                                {
                                <li> 
                                <input id="@row.Id" type="checkbox"  name="Consumption" datatype="max2" value="@row.Id" /> 
                                <label for="@row.Id">@row.Crowd  [消费券]</label> 
                                </li>  }
                                if (row.DeedType == 3)
                                {
                                <li> 
                                <input id="@row.Id" type="checkbox"  name="Advertis" datatype="max2" value="@row.Id" /> 
                                <label for="@row.Id">@row.Crowd  [广告券]</label> 
                                </li>  }
                              }
                            } 
                        </ul>
                    } 
                </dd>
            </dl>   }  
            <script>
                $(function() {
                    //用户积分
                    $('#Seetlement_JF').change(function() {
                        var a = $("#Seetlement_OrderAmount").val();
                        var userIntegration = $("#UserIntegration").val();
                        //alert(userIntegration);
                        var b = $(this).val();
                        var aa = a * 100;
                        if (parseInt(b) > parseInt(userIntegration)) {
                            alert("您当前积分为：" + userIntegration);
                            $(this).val(userIntegration);
                        }
                        if (b > aa) {
                            alert("积分最大输入为：" + aa);
                            $(this).val(aa);
                        }
                        $("#Seetlement_Amount").focus();
                    }); 
                    //用户优惠券
                    $(':checkbox[name="chkItem"]').click(function() {
                        $("#Seetlement_Amount").focus();
                    });
                    $("#Seetlement_Amount").focus(function () {
                        var theOrderAmount = $("#Seetlement_OrderAmount").val();
                        var ccccc = parseFloat($('#Seetlement_JF').val()) / 100;
                        var youhuiquan = 0;
                        for (var i = 0; i < this.form.chkItem.length; i++) {
                            if (this.form.chkItem[i].type == 'checkbox') {
                                if (this.form.chkItem[i].checked) {
                                    youhuiquan += parseFloat(this.form.chkItem[i].value);
                                }
                            }
                        }
                        this.value = parseFloat(theOrderAmount) - ccccc - youhuiquan;
                        $("#Seetlement_PaidAmount").focus();
                    });
                     
                    
                    $('#Seetlement_DisAmount').change(function () {
                        $("#Seetlement_PaidAmount").focus();
                    });

                    $("#Seetlement_PaidAmount").focus(function() {
                        var amount = parseFloat($("#Seetlement_Amount").val());
                        var disAmount = parseFloat($("#Seetlement_DisAmount").val());
                        this.value = amount - disAmount;
                        $("#Seetlement_GiveAmount").focus();
                    });
                     
                    $('#Seetlement_RecAmount').change(function () {
                        $("#Seetlement_GiveAmount").focus();
                    }); 
                    $("#Seetlement_GiveAmount").focus(function () {
                        var paidAmount = parseFloat($("#Seetlement_PaidAmount").val());
                        var recAmount = parseFloat($("#Seetlement_RecAmount").val());
                        this.value = recAmount - paidAmount;
                    }); 
                });  
            </script>
       
        } 
        <dl>
            <dt>应付金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.Amount, null, new { @class = "input small jine", @readonly = "readonly" })元
            </dd> 
        </dl>
        <dl>
            <dt>优惠金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.DisAmount, "0", new { @class = "input small jine" }) 元</dd>

        </dl>
        <dl>
            <dt>实收金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.PaidAmount, null, new { @class = "input small jine", @readonly = "readonly" ,datatype = "ck", errormsg = "实收金额不能小于零元" })元</dd> 
        </dl>
        <dl>
            <dt>收到金额：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.RecAmount, null, new { @class = "input small jine" })元</dd> 
        </dl> 
        <dl>
            <dt>现金找零：</dt>
            <dd>@Html.TextBoxFor(model => model.Seetlement.GiveAmount, null, new { @class = "input small jine", datatype = "ck", @readonly = "readonly", errormsg = "现金找零不能小于零元" })元</dd>
         </dl> 
        @{
                                                   if (Model.HotelDeed.Any() && Model.User != null)
                                                   {
            <dl>
                <dt>店铺优惠券：</dt>
                <dd> 
                    <ul>     
                        @foreach (var row in Model.HotelDeed)
                        {
                            <li>
                                  <input id="@row.Id" type="checkbox"  name="HotelDeedCKB" value="@row.Id" /> 
                                  <label for="@row.Id">@row.Crowd </label> 
                            </li>    
                        }
                        </ul> 
                </dd>
            </dl> 
                                                   } 
        } 
    </div>   
    <div class="tab-content" style="display: none">
        <table class="ltable">
            <tr>
                <td></td>
                <td>商品名称</td>
                <td>单价</td>
                <td>数量</td>
                <td>金额</td>
            </tr>
            @if (null != ViewData.Model.OrderDetailsModel)
            {
                foreach (var item in ViewData.Model.OrderDetailsModel)
                {
                <tr>
                    <td>&nbsp;</td>
                    <td>@item.CName</td>
                    <td>@item.Price</td>
                    <td>@item.Num</td>
                    <td>@(item.Price * item.Num)</td>
                </tr>
                }
            }
        </table>
    </div> 
     
    <div class="line10"></div> 

    <div class="btn-list">
        <input type="submit" value="结账" id="btnjiesuan" class="btn" />
    </div>
    <script> 
        $(function () { 
            //金额不能小于0
            $.extend($.Datatype, {
                "ck": function (gets, obj, curform, regxp) {
                    if (parseInt(gets) < 0) {
                        return false;
                    }
                    return true;
                },
                "max2": function (gets, obj, curform, regxp) {
                    var atmax = 1,
                        numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;

                    if (numselected > atmax) {
                        return "每种优惠券最多只能选择" + atmax + "项！";
                    }
                    return true;
                }
            });
        });
        var isok = false;
        function OnSuccess(s) {
            window.location.href = "@Url.Action("OrderPint", "Print")?orderid=" + s;
        } 
    </script> 
   
}*@